package main

import "fmt"

type ListNode struct {
	Val  int
	Next *ListNode
}

func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {
	if list1 == nil {
		return list2
	}
	if list2 == nil {
		return list1
	}
	temp1 := list1
	temp2 := list2
	newList := &ListNode{}
	temp3 := newList
	for {
		if temp1 == nil && temp2 == nil {
			break
		}
		if temp1 != nil && temp2 == nil {
			fmt.Println(2)
			temp3.Next = temp1
			break
		}
		if temp2 != nil && temp1 == nil {
			temp3.Next = temp2
			break
		}
		if temp1.Val > temp2.Val {
			fmt.Println(1)
			node := &ListNode{}
			node.Val = temp2.Val
			temp3.Next = node
			temp3 = temp3.Next
			temp2 = temp2.Next
		} else if temp1.Val < temp2.Val {
			fmt.Println(2)
			node := &ListNode{}
			node.Val = temp1.Val
			temp3.Next = node
			temp3 = temp3.Next
			temp1 = temp1.Next
		} else {
			node1 := &ListNode{}
			node2 := &ListNode{}
			node1.Val = temp1.Val
			temp3.Next = node1
			temp3 = temp3.Next
			node2.Val = temp2.Val
			temp3.Next = node2
			temp3 = temp3.Next
			temp1 = temp1.Next
			temp2 = temp2.Next
		}

	}
	return newList.Next
}
func main() {
	//list1:=&ListNode{}
	//node1:=&ListNode{1,nil}
	//node2:=&ListNode{2,nil}
	//node3:=&ListNode{4,nil}
	//list1.Next=node1
	//node1.Next=node2
	//node2.Next=node3
	//list2:=&ListNode{}
	//node4:=&ListNode{1,nil}
	//node5:=&ListNode{3,nil}
	//node6:=&ListNode{4,nil}
	//list2.Next=node4
	//node4.Next=node5
	//node5.Next=node6
	list1 := &ListNode{2, nil}
	list2 := &ListNode{1, nil}
	newList := mergeTwoLists(list1, list2)
	for {
		if newList == nil {
			break
		}
		fmt.Printf("[%d]=>", newList.Val)
		newList = newList.Next
	}
}
